/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dawnland02.data.map.service;

import java.util.*;

import dawnland02.data.map.algorithm.astar.AStarAlgorithm;
import dawnland02.data.map.io.reader.MatrixXMLReader;
import dawnland02.data.map.io.reader.sax.MatrixXMLSAXReader;
import dawnland02.data.map.model.Matrix;
import dawnland02.data.map.model.MatrixCell;
import dawnland02.model.entity.Entity;

/**
 * @author Petru Obreja (obrejap@yahoo.com)
 */
public class MatrixService {
    private static MatrixXMLReader matrixXMLReader;
    private static AStarAlgorithm aStarAlgorithm;

    public static Matrix readMatrix(String fileName){
        return getMatrixXMLReader().readMatrix(fileName);
    }

    public static List<MatrixCell> getClosestPath(Entity entity, Matrix matrix, int xStart, int yStart, int xFinish, int yFinish){
        return getAStarAlgorithm().getClosestPath(entity, matrix, xStart, yStart, xFinish, yFinish);
    }

    private static MatrixXMLReader getMatrixXMLReader() {
        if(matrixXMLReader == null){
            matrixXMLReader = new MatrixXMLSAXReader();
        }
        return matrixXMLReader;
    }

    private static AStarAlgorithm getAStarAlgorithm() {
        if(aStarAlgorithm==null){
            aStarAlgorithm = new AStarAlgorithm();
        }
        return aStarAlgorithm;
    }
}
